<template>
  <Modal :title="title" v-model="model" :width=800>
    <Form ref="showdata" :model="obj" :label-width="160" :rules="ruleCustom">
      <Row type="flex" justify="space-around">
        <Col span="23">
          <FormItem label="二级集团安全审计负责人：" prop="user1">
            <Select v-model="obj.user1">
              <Option v-for="item in secondaryGroupPersionList" :value="item.userId" :key="item.userId">
                {{ item.userName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
    </Form>
    <div slot="footer">
      <Button class='ivu-btn-save' :loading="loading" @click="submit('showdata')">确定</Button>
      <Button class='ivu-btn-cancel' @click="handleCancel">取消</Button>
    </div>
  </Modal>
</template>

<script>


import {Api} from "@/api";
import {sessionStorage} from "@/common/cacheUtils";

export default {
  name: "auditSubmit",
  props: {
    title: {
      type: String
    },
    data: {
      type: Object,
    }
  },
  data() {
    return {
      user: sessionStorage('userId').getObject('userId'),
      model: false,
      obj: {},
      data: {},
      secondaryGroupPersionList: [],
      loading: false,
      ruleCustom: {
        user1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else if (value < 0) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

      },
    }
  },
  async mounted() {
    await this.selectCodingSort()
  },
  methods: {
    showAudit() {
      this.model = true;
    },
    handleCancel() {
      this.model = false;
    },
    async selectCodingSort() {
      //二级集团
      await this.$http.get(Api.queryRoleUser + "/" + "843197356dd443d099542d7ebe22b2be", {
        params: {
          orgId: sessionStorage('userId').getObject('userId').twoLevelOrgId,
          two: true
        }
      }).then((res) => {
        this.secondaryGroupPersionList = res.data.data;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      });
    },
    submit(name) {
      let _this = this;
      this.$refs[name].validate((valid) => {
        if (valid) {
          _this.loading = true;
          _this.obj.createUserId = this.user.userId;
          _this.obj.userName = this.user.userName;
          debugger;
          this.$http.post(Api.submit, _this.obj).then(res => {
            if (res.data.status === 200) {
              this.$Message.success("上报成功");
              this.$emit("success")
              _this.loading = false;
              _this.model = false;
            } else {
              this.$Message.error(res.data.msg);
            }
          })
        } else {
          this.$Message.error('请填报完整!');
        }
      })
    },
  },
  watch: {
    data: {
      handler(newVal, oldVal) {
        console.log(newVal)
        this.obj = newVal;
      },
      deep: true,
    }

  }

}
</script>

<style lang='css' scoped>
@import '../../../index.css';
</style>
